package 面试.单例模式;

import java.util.concurrent.*;

public class Test {
    public static void main(String[] args) {
        Singleton1 s = Singleton1.INSTANCE;
        System.out.println(s);
    }
}
class TestSingleton2{
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        Callable<Singleton2> c = new Callable<Singleton2>() {
            @Override
            public Singleton2 call() throws Exception {
                return Singleton2.getInstance();
            }
        };
        ExecutorService es = Executors.newFixedThreadPool(2);
        Future<Singleton2> f1 = es.submit(c);
        Future<Singleton2> f2 = es.submit(c);

        Singleton2 s1 = f1.get();
        Singleton2 s2 = f2.get();

        System.out.println(s1==s2);
        System.out.println(s1);
        System.out.println(s2);

        es.shutdown();

    }
}
